import java.sql.*;

public class SetItem {
    public static void main(String[] args) {
        if (args.length < 7)
        {
            System.out.println("USAGE: java -cp .:/usr/share/java/* SetItem root password title desc price bname auctionend");
            return;
        }
        String url = "jdbc:mysql://localhost:3306/bidsys";  

        addItem (url, args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
    }

    public static void addItem (String url,
        String username, String password, String title, String desc, String price, String bname, String auctionend)
    {
    	Connection conn = null;
    	CallableStatement call = null;
        try {
            DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            //password=null;  // If you haven't set one for MySQL root user.
            conn = DriverManager.getConnection(url, username, password);

            call = conn.prepareCall("{CALL add_item (?,?,?,?,?,?,?) }");

            // Find out what all the items are. line 24
            call.registerOutParameter(1, Types.INTEGER);
            call.setString(2, title);
            call.setString(3, desc);
            call.setString(4, price);
            call.setString(5, bname);
            call.setString(6, auctionend);
            call.setString(7, null);
            call.executeUpdate();
            int  iRetVal = call.getInt(1);
            System.out.println(iRetVal);
        } catch (SQLException sqle) {
            // Online Hack Fix for MySQL 5.0 my_signal
            String msg = sqle.toString();  
            System.err.println ("SQL Error: " + msg);
        } catch (Exception e) {
            System.out.println("Error: " + e);
        } finally {
            try {
                if (call != null)
                    call.close();
                if (conn != null)
                    conn.close();
            } catch (SQLException sqle) {
                sqle.printStackTrace();
            }
        }
    }
}

